package node;

import lexer.LexType;
import parser.Parser;

import java.io.IOException;

public class FuncDefNode extends ASTNode {
    public final String name = "<FuncDef>";
    // FuncDef → FuncType Ident '(' [FuncFParams] ')' Block
    private final FuncTypeNode funcTypeNode;
    private final String identNode;
    private final FuncFParamsNode funcFParamsNode;
    private BlockNode blockNode;

    public FuncDefNode(FuncTypeNode funcTypeNode, String identNode, FuncFParamsNode funcFParamsNode,
            BlockNode blockNode) {
        this.funcTypeNode = funcTypeNode;
        this.identNode = identNode;
        this.funcFParamsNode = funcFParamsNode;
        this.blockNode = blockNode;
    }

    public FuncDefNode(FuncTypeNode funcTypeNode, String identNode, FuncFParamsNode funcFParamsNode) {
        this.funcTypeNode = funcTypeNode;
        this.identNode = identNode;
        this.funcFParamsNode = funcFParamsNode;
    }

    @Override
    public void show() throws IOException {
        funcTypeNode.show();
        Parser.parserWriter.write(LexType.IDENFR + " " + identNode + "\n");
        Parser.parserWriter.write(LexType.LPARENT + " " + "(" + "\n");

        if (funcFParamsNode != null) {
            funcFParamsNode.show();
        }

        Parser.parserWriter.write(LexType.RPARENT + " " + ")" + "\n");
        blockNode.show();
        Parser.parserWriter.write(name + "\n");
    }

    public String getIdentNode() {
        return identNode;
    }

    public FuncTypeNode getFuncTypeNode() {
        return funcTypeNode;
    }

    public FuncFParamsNode getFuncFParamsNode() {
        return funcFParamsNode;
    }
}
